#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e6+10;
int sk[maxn];
int skmin[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int sktop = 0,skmintop = 0;
		for(int i = 0;i<n;i++)
		{
			char s[5];
			int val;
			scanf("%s",s);
			if(strcmp(s,"MIN")==0)
			{
				if(!sktop) puts("NULL");
				else printf("%d\n",skmin[skmintop]);
			}
			else if(strcmp(s,"PUSH")==0)
			{
				scanf("%d",&val);
				sk[++sktop] = val;
				if(val<=skmin[skmintop]||skmintop==0) skmin[++skmintop]=val;
				else skmin[++skmintop] = skmin[skmintop-1]; 
			}
			else 
			{	
				sktop--;
				skmintop--;
			}
		}
		
	}
}
